<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.getAbilitaz.php');
$aAbilitaz = getAbilitaz();

if (reqVar('azione') == 'elimina') {
	$msgPag .= confElim();
} 
$sqlSel = "SELECT * FROM rgl_ruoli " .
		" WHERE id_ruolo = ".intval(reqVar('id'));
$objDB->query($sqlSel,'selRec');
if (!$acRec = $objDB->fetch('selRec')) {
	backOnErr("var. id. '".reqVar('id')."' mancante o errato");
}
$_REQUEST = array_merge($acRec,$_REQUEST);

$sSql = "SELECT * FROM rgl_ruoli_abilitaz " .
		" WHERE id_ruolo = ".intval(reqVar('id'));
$objDB->query($sSql);
$aValAbilitaz = array();
while($acX = $objDB->fetch()) {
	$aValAbilitaz[$acX['cod_abilitaz']] = $acX['valore'];
}
//dbg_($aValAbilitaz);

$cmdL = "";
$cmdL .= "&nbsp;&nbsp;&nbsp;";
$sCmdPagR = '';
if (true) {
	$sCmdPagR .= "&nbsp;&nbsp;&nbsp;";
	$sCmdPagR .= "<a class='cmd1' href='ruoliMod.php?id=".reqVar('id')."&$sXSNQS' >modifica</a>";
	$sCmdPagR .= "&nbsp;&nbsp;&nbsp;";
	$sCmdPagR .= "<a class='cmd1' href='#' onclick='confElim();' >elimina</a>";
}
$sCmdPagR .= cmdTorna(); 

testaHtml('Gestione applicazione',$msgPag,'gest');
?>
<script language="JavaScript" type="text/javascript">
  	function confElim() {
  		if (confirm("Confermi l'eliminazione dell'ruolo ?")) {
  			document.location.href = "<?=$_SERVER['PHP_SELF']."?id=".reqVar('id')."&azione=elimina&".$sXSNQS?>";
  		}
  	}
</script>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left"><?=$cmdL?></td>
      <td class="cmd1" align="right"><?=$sCmdPagR?></td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<? 
echo getHtmlRigaRif();
?>
   <tr>
      <td class="tit1" colspan='20' align='center'>
			RUOLO
		</td>
   </tr>
<?
$aCamForm = array();
require("_inc/const.campiRuolo.php");
unset($aCamForm[40]);
echo getHtmlCampiForm($aCamForm,'vis');
?>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="tit1" colspan='5' align='center'>
			Abilitazioni
		</td>
   </tr>
	<tr>
		<td class="lab1" width='40%' align='center'>Descrizione</td>
		<td class="lab1" width='10%' align='center'>Flag</td>
		<td class="lab1" width='40%' align='center'>Descrizione</td>
		<td class="lab1" width='10%' align='center'>Codice</td>
   </tr>
<?
$clRF='txt2';
$p1 = $p2 = 0;
foreach($aAbilitaz as $abX => $aAbX) {
	$clRF = ($clRF=='txt1')?'txt2':'txt1';	
	if (strlen($abX)>4) {
		$p2++;
		$indent="<td class='$clRF' width='30'>&nbsp;</td>";
		$numeraz = $p1.".".$p2."&nbsp;-";
	} else {
		$p1++;
		$p2=0;
		$indent = "<td class='$clRF' width='1'>&nbsp;</td>";
		$numeraz = $p1."&nbsp;-";
	}
	$bold="font-weight:bold;";
	if (isset($aValAbilitaz[$abX])) {
		$flagX = $aValAbilitaz[$abX];		
	} else {
		$flagX = $aAbX['def'];
	}
	$desFlagX = $aAbX['val'][$flagX]['des'];
	if ($flagX == $aAbX['def']) {
		continue; //$desFlagX .= " (default)";
	}
?>
	<tr>
		<td class="<?=$clRF?>" align='left' valign='top'>
			<table cellspacing='0' cellpadding='0'>
				<tr><?=$indent?>
					<td align='right' class='<?=$clRF?>' width='30'><?=$numeraz?>&nbsp;</td>
					<td style='<?=$bold?>' class="<?=$clRF?>" valign='top'><?=$aAbX['des']?></td>
				</tr>
				<tr><?=$indent?>
					<td align='right' class='<?=$clRF?>'>&nbsp;</td>
					<td class="<?=$clRF?>"><?=$aAbX['not']?></td>
				</tr>
			</table>
		</td>
		<td class="<?=$clRF?>" align='center' valign='top'>
			<?=$flagX?>
		</td>
		<td class="<?=$clRF?>" align='left' valign='top'>
			<?=$desFlagX?>
		</td>
		<td class="<?=$clRF?>" style='font-family:lucida console,courier;' valign='top'>
			<?=$abX?>
		</td>
	</tr>
<?
}
?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right"><?=$sCmdPagR?></td>
   </tr>
</table>
<?
codaHtml();
exit();
function confElim() {
	global $objDB;
	$msg = '';
	$sSqlDel = "SELECT id_ruolo FROM xxxx WHERE id_ruolo = ".intval(reqvar('id'));
	#$objDB->exec($sSqlDel);
	#if ($acX=$objDB->fetch()) {
	#	$msg .= "esistono operazioni per questo ruolo<br>";
	#}
	if ($msg != '') {
		return $msg;
	}
	$sSqlDel = "DELETE FROM rgl_ruoli WHERE id_ruolo = ".intval(reqvar('id'));
	$objDB->exec($sSqlDel);
	//return "<pre>".print_r($objDB,1)."</pre>";
	header("Location: ruoloList.php?msgpag=".urlencode('ruolo eliminato')."&xsn=".XSN);
	exit();
}
?>